﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class OrderDetail
    {
        private readonly Chain.IDAL.OrderDetail dal = new Chain.IDAL.OrderDetail();

        public int Add(Chain.Model.OrderDetail model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.OrderDetail> DataTableToList(DataTable dt)
        {
            List<Chain.Model.OrderDetail> list = new List<Chain.Model.OrderDetail>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.OrderDetail item = new Chain.Model.OrderDetail();
                    if ((dt.Rows[i]["OrderDetailID"] != null) && (dt.Rows[i]["OrderDetailID"].ToString() != ""))
                    {
                        item.OrderDetailID = int.Parse(dt.Rows[i]["OrderDetailID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderID"] != null) && (dt.Rows[i]["OrderID"].ToString() != ""))
                    {
                        item.OrderID = int.Parse(dt.Rows[i]["OrderID"].ToString());
                    }
                    if ((dt.Rows[i]["GoodsID"] != null) && (dt.Rows[i]["GoodsID"].ToString() != ""))
                    {
                        item.GoodsID = int.Parse(dt.Rows[i]["GoodsID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderDetailPrice"] != null) && (dt.Rows[i]["OrderDetailPrice"].ToString() != ""))
                    {
                        item.OrderDetailPrice = decimal.Parse(dt.Rows[i]["OrderDetailPrice"].ToString());
                    }
                    if ((dt.Rows[i]["OrderDetailPoint"] != null) && (dt.Rows[i]["OrderDetailPoint"].ToString() != ""))
                    {
                        item.OrderDetailPoint = int.Parse(dt.Rows[i]["OrderDetailPoint"].ToString());
                    }
                    if ((dt.Rows[i]["OrderDetailDiscountPrice"] != null) && (dt.Rows[i]["OrderDetailDiscountPrice"].ToString() != ""))
                    {
                        item.OrderDetailDiscountPrice = decimal.Parse(dt.Rows[i]["OrderDetailDiscountPrice"].ToString());
                    }
                    if ((dt.Rows[i]["OrderDetailNumber"] != null) && (dt.Rows[i]["OrderDetailNumber"].ToString() != ""))
                    {
                        item.OrderDetailNumber = decimal.Parse(dt.Rows[i]["OrderDetailNumber"].ToString());
                    }
                    if ((dt.Rows[i]["OrderDetailType"] != null) && (dt.Rows[i]["OrderDetailType"].ToString() != ""))
                    {
                        item.OrderDetailType = int.Parse(dt.Rows[i]["OrderDetailType"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int OrderDetailID)
        {
            return this.dal.Delete(OrderDetailID);
        }

        public int DeleteDetail(int inOrderID)
        {
            return this.dal.DeleteDetail(inOrderID);
        }

        public int DeleteItem(int intOrder, int intGoodsID)
        {
            return this.dal.DeleteItem(intOrder, intGoodsID);
        }

        public bool DeleteList(string OrderDetailIDlist)
        {
            return this.dal.DeleteList(OrderDetailIDlist);
        }

        public bool Exists(int OrderDetailID)
        {
            return this.dal.Exists(OrderDetailID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetDetail(int intOrderID)
        {
            return this.dal.GetDetail(intOrderID);
        }

        public DataSet GetExpenseDetail(int PageSiza, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetExpenseDetail(PageSiza, PageIndex, out resCount, strWhere);
        }

        public DataSet GetGoodsExpenseDetail(string strWhere)
        {
            return this.dal.GetGoodsExpenseDetail(strWhere);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(string strWhere)
        {
            return this.dal.GetListSP(strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.OrderDetail GetModel(int OrderDetailID)
        {
            return this.dal.GetModel(OrderDetailID);
        }

        public List<Chain.Model.OrderDetail> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetOrderDetail(string strWhere)
        {
            return this.dal.GetOrderDetail(strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public string ProjectName(int OrderMemID, int OrderID)
        {
            return this.dal.ProjectName(OrderMemID, OrderID);
        }

        public int Update(Chain.Model.OrderDetail model)
        {
            return this.dal.Update(model);
        }
    }
}

